package com.bodgittandscarper.broker.types.impl;

import java.util.Arrays;

import com.bodgittandscarper.broker.types.RecordMod;

/**
 * Implementation class of the {@link com.bodgittandscarper.broker.types.RecordMod} 
 * 
 * @author Morten Rummelhoff
 *
 */
public class RecordImpl implements RecordMod {
	
	/**
	 * Version number for serializable object.  
	 */
	private static final long serialVersionUID = 1790047346797733948L;
	private String[] fields;
	private boolean isValid;
	private int recordNumber;
	private boolean isLocked;
	
	/**
	 * Construtor specifying recordNumber, record validity, locked state and fields.
	 * 
	 * @param recordNumber The record number
	 * @param isValid Whether or not record is valid
	 * @param isLocked Whether or not record is locked
	 * @param fields The data of the Record
	 */
	public RecordImpl (int recordNumber, boolean isValid, boolean isLocked, String[] fields) {
		this.isValid = isValid;
		this.isLocked = isLocked;
		this.fields = fields;
		this.recordNumber = recordNumber;
	}
	
	@Override
	public String[] getRecordFields() {
		return fields;
	}
	@Override
	public void updateRecordFields(String[] data) {
		fields = data;
	}
	@Override
	public boolean isValid() {
		return isValid;
	}
	@Override
	public void setValid(boolean valid) {
		isValid = valid;
	}
	@Override
	public int getRecordNumber() {
		return recordNumber;
	}

	@Override
	public void lock() {
		isLocked = true;	
	}

	@Override
	public void unlock() {
		isLocked = false;
	}
	
	@Override
	public boolean isLocked() {
		return isLocked;
	}
	
	public String toString() {
		return "Number: " + getRecordNumber() +  
			"IsValid: " + isValid() + 
			"IsLocked: " + isLocked() + 
			"Fields: " + Arrays.toString(getRecordFields()) + "\n";
	}

	
	
}
